package org.example.controller;

import org.example.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("/set")
    public String set(@RequestParam String key, @RequestParam String value) {
        redisUtil.setWithExpire(key, value,60, TimeUnit.SECONDS);
        return "Set key: " + key + ", value: " + value;
    }

    @GetMapping("/get")
    public Object get(@RequestParam String key) {
        return redisUtil.get(key);
    }

    @GetMapping("/delete")
    public String delete(@RequestParam String key) {
        redisUtil.delete(key);
        return "Deleted key: " + key;
    }
}
